/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package eu.bopet.jocadv.core.elements;

import eu.bopet.jocadv.core.Element;
import eu.bopet.jocadv.core.Optimizable;
import java.io.Serializable;
import java.util.Arrays;
import org.apache.commons.math3.geometry.euclidean.threed.Vector3D;

/**
 * The class represents lines in three dimensional space
 *
 * @author bocskapeter
 */
public class Line extends Element implements Serializable, Optimizable {

    /**
     * Numbers of the line end points
     */
    public static final int ENDPOINTS = 2;

    // end points
    private Vector3D[] endPoint;

    /**
     * Builds a new line with the two given end points
     *
     * @param endPoint1
     * @param endPoint2
     * @return Line
     */
    public Line getNewLine(Vector3D endPoint1, Vector3D endPoint2) {
        Line line = new Line("Line");
        endPoint = new Vector3D[ENDPOINTS];
        endPoint[0] = endPoint1;
        endPoint[1] = endPoint2;
        return line;
    }

    /**
     * Default constructor
     *
     * @param name
     */
    public Line(String name) {
        super(name);
        this.endPoint = new Vector3D[ENDPOINTS];
    }

    /**
     * Gets the end points
     *
     * @return point as Vector3D[]
     */
    public Vector3D[] getEndPoint() {
        return endPoint;
    }

    /**
     * Sets the end points
     *
     * @param endPoint1 as Vector3D
     * @param endPoint2 as Vector3D
     */
    public void setEndPoint(Vector3D endPoint1, Vector3D endPoint2) {
        this.endPoint[0] = endPoint1;
        this.endPoint[1] = endPoint2;
    }

    /**
     * Converts to String
     *
     * @return Sting
     */
    @Override
    public String toString() {
        return "\n Line{" + super.toString() + "endPoint=" + Arrays.toString(endPoint) + '}';
    }

    /**
     * Gives the point (variables) of the equation
     *
     * @return array of double values
     */
    @Override
    public double[] getVaraiables() {
        return new double[]{this.endPoint[0].getX(), this.endPoint[0].getY(), this.endPoint[0].getZ(), this.endPoint[1].getX(), this.endPoint[1].getY(), this.endPoint[1].getZ()};
    }

}
